package cn.edu.scau.cmi.dengzejun.chapter11;

import javax.swing.*;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

public class WindowMenu extends JFrame{
	JMenuBar menubar;
	JMenu menu,subMenu;
	JMenuItem item1,item2;
	public WindowMenu() {
		
	}
	
	public WindowMenu(String s,int x,int y ,int w,int h) {
		init(s);
		setLocation(x,y);
		setSize(w,h);
		setVisible(true);
		this.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
	}
	
	void init(String s) {
		this.setTitle(s);
		this.menubar = new JMenuBar();
		this.menu = new JMenu("Menu");
		this.subMenu = new JMenu("Software project");
		this.item1 = new JMenuItem("Java topic");
		this.item2 = new JMenuItem("Animation topic");
		this.item1.setAccelerator(KeyStroke.getKeyStroke('A'));
		this.item2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));
		this.menu.add(item1);
		this.menu.add(item2);
		this.menu.addSeparator();
		this.menu.add(subMenu);
		this.subMenu.add(new JMenuItem("Car sales System"));
		this.subMenu.add(new JMenuItem("Farm infomation System"));
		this.menubar.add(menu);
		setJMenuBar(this.menubar);
		return;
	}
}
